import 'package:flutter/material.dart';
import 'package:s_mankey/config/net/smonkey_api.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/error_widget.dart';
import 'package:s_mankey/ui/widget/loading_widget.dart';
import 'package:s_mankey/ui/widget/unlogin_nav.dart';

class StudentAuthenticat extends StatefulWidget {
  StudentAuthenticat({Key key}) : super(key: key);

  @override
  _StudentAuthenticat createState() => _StudentAuthenticat();
}


class _StudentAuthenticat extends State<StudentAuthenticat> {

  Map<String, dynamic> datas; //用户数据
  Map<String, dynamic> list;  //把用户数据重构为UI可用数据
  Map<String, dynamic> tellDatas;


  @override
  void initState() {

    UnLoginNav(context).unLogin();

    list = {
      "student_no": ['学员编号:', null],
      "chi_name": ["真实姓名:", null],
      "mobile": ["电话号码:", null],
      "hkid": ['身份证号码', null],
      "email": ['邮箱', null]
    };
    super.initState();
  }

  ///初始化数据
  Future initDatas() async {
    List<Future> futures = [];
    futures
      ..add(SmonkeysRepository.fetchIsIdentify())
      ..add(SmonkeysRepository.fetchTellMe());
    return await Future.wait(futures);
  }

  @override
  Widget build(BuildContext context) {
   return Scaffold(
       backgroundColor: Colors.white,
       appBar: AppBar(
         backgroundColor: Color(0xfff9f9f9),
         elevation: 0,
         title: Text('学员认证'),
       ),
       body: FutureBuilder(future: initDatas(),builder:
    (BuildContext context, AsyncSnapshot snapshot) {

    /// 请求中
    if (snapshot.connectionState != ConnectionState.done) {
    return LoadingWidget();
    }
    /// 请求结束
    if (snapshot.hasError) {
    // 请求失败，显示错误
//      print('snapshot.data${snapshot.data['message']}');
//      print('snapshot.data${snapshot.error}');

    return datasErrorWidget(errorTip: snapshot.error.toString(),);
    }

    datas = snapshot.data[0];
    tellDatas = snapshot.data[1];
    datas.forEach((key, value) {
      list[key][1] = value.toString();
    });


    // 请求成功，显示数据
    return Text('123');
//      Column(
//         children: [
//           ListView.builder(
//             shrinkWrap: true,
//             physics: NeverScrollableScrollPhysics(),
//             padding: EdgeInsets.only(top: 0),
//             itemCount: list.length,
//             itemBuilder: (BuildContext context, int index) {
//               return Container(
//                 child: Column(
//                   children: [
//                     Container(
//                       height: 44,
//                       child: Row(
//                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
//                         children: [
//                           Padding(
//                             padding: const EdgeInsets.only(left: 10),
//                             child: Text(
//                               list.values.toList()[index][0],
//                               style: TextStyle(color: Color(0xff2b2b2b),fontSize: AppFontSize.Size14),
//                             ),
//                           ),
//                           Padding(
//                             padding: const EdgeInsets.only(right: 10),
//                             child: Text(list.values.toList()[index][1],
//                                 style: TextStyle(color: Color(0xff545454), fontSize: AppFontSize.Size14)),
//                           )
//                         ],
//                       ),
//                     ),
//                     AppCommonWidget.dividerCommon,
//                   ],
//                 ),
//               );
//             },
//           ),
//
//           Padding(
//             padding: const EdgeInsets.only(top: 50),
//             child: Image.network(
//               'https://dss0.bdstatic.com/6Ox1bjeh1BF3odCf/it/u=829888290,2650878176&fm=74&app=80&f=JPG&size=f121,121?sec=1880279984&t=274501980523d63a7d93c94f85aabbab',
//               width: 85,
//               height: 85,
//               fit: BoxFit.fill,
//             ),
//           ),
//           Padding(
//             padding: const EdgeInsets.only(top: 50),
//             child: Column(
//               mainAxisAlignment: MainAxisAlignment.center,
//               crossAxisAlignment: CrossAxisAlignment.center,
//               children: [
//                 Text('平台联系方式',style: TextStyle(color: Colors.black),),
//                 contactText(title: '微信：', subTitle: tellDatas['wechat']),
//                 contactText(
//                     title: '邮箱：', subTitle: tellDatas['email']),
//               ],
//             ),
//           ),
//         ],
//       );
       }),);
  }


  /// 底部联络方式样式
  Widget contactText({String title, String, subTitle}) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text(
          title,
          style: TextStyle(fontSize: AppFontSize.Size14),
        ),
        Text(subTitle, style: TextStyle(fontSize: AppFontSize.Size12))
      ],
    );
  }
}